<template>
  <cl-dialog :title="`${type == 'add' ? '新增' : '修改'}支付方式`" center :visible.sync="visible" width="50%" @close="close">
    <el-form :model="formData" ref="form" label-width="100px" label-position="top" class="demo-form">
      <el-form-item label="门店" prop="dept_id" :rules="[{ required: true, message: '请选择门店' }]">
        <cl-shop-select :disabled="type == 'edit'" v-model="formData.dept_id" clearable :biz_id="biz_id"
          style="width: 100%" filterable/>
      </el-form-item>
      <el-form-item label="支付名称" prop="pay_name" :rules="[{ required: true, message: '请输入支付名称' }]">
        <el-input v-model="formData.pay_name"></el-input>
      </el-form-item>
      <el-form-item label="类型" prop="type" :rules="[{ required: false, message: '请选择类型' }]">
        <cl-select v-model="formData.type" style="width: 100%">
          <el-option label="线上" :value="1" />
          <el-option label="线下" :value="2" />
        </cl-select>
      </el-form-item>
      <el-form-item label="账户/商户号" prop="bank_account" :rules="[{ required: false, message: '请输入账户/商户号' }]">
        <el-input v-model="formData.bank_account" placeholder="请输入账号/商户号" />
      </el-form-item>
      <el-form-item label="账户全称" prop="bank_account_name" :rules="[{ required: false, message: '请输入账户全称' }]">
        <el-input v-model="formData.bank_account_name" placeholder="请输入账户全称" />
      </el-form-item>
      <el-form-item label="银行名称" prop="bank_name" :rules="[{ required: false, message: '请输入银行名称' }]">
        <el-input v-model="formData.bank_name" placeholder="请输入账户全称" />
      </el-form-item>
      <el-form-item label="类型公/私" prop="bank_account_type" :rules="[{ required: false, message: '请选择类型公/私' }]">
        <cl-select v-model="formData.bank_account_type" placeholder="请选择支付方式" style="width: 100%">
          <el-option label="对公" :value="1" />
          <el-option label="对私" :value="2" />
        </cl-select>
      </el-form-item>
      <el-form-item label="收款方" prop="payee" :rules="[{ required: true, message: '请选择收款方' }]">
        <cl-select v-model="formData.payee" placeholder="请选择收款方" filterable style="width: 100%">
          <el-option label="我方" :value="1" />
          <el-option label="院方" :value="2" />
          <el-option label="第三方" :value="3" />
        </cl-select>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="formData.remark"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">关闭</el-button>
      <el-button type="primary" :loading="saving" @click="submit">确定</el-button>
    </template>
  </cl-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      type: '',
      formData: {

      },
      biz_id: '',
      saving: false
    }
  },
  created() {
    this.biz_id = this.getCurrBiz();
  },
  mounted() {

  },
  methods: {
    open() {
      this.visible = true;
      console.log('出发');

    },
    setData(type, data) {
      this.type = type
      if (data) {
        this.formData = this.$TOOL.objCopy(data)
      }
    },
    close() {
      this.formData = {};
      this.visible = false;
    },
    submit() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          this.saving = true
          let params = this.$TOOL.objCopy(this.formData)
          try {
            if (this.type == "add") {
              await this.$service.reconciliation.addDeptPaymentWay(params)
            } else {
              await this.$service.reconciliation.editDeptPaymentWay(params)
            }
            this.saving = false
            this.close()
            this.$emit("successed");


          } catch (error) {
            this.saving = false
          }
        }
      })
    }
  },
}
</script>
<style scoped lang='scss'></style>
